package com.sgb.kjwl.view.widget.pricecheck;

import android.content.Context;

import androidx.recyclerview.widget.LinearLayoutManager;

import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pricecheck.AttributeViewEntity;
import com.sgb.kjwl.view.ui.adapter.pricecheck.AttributeViewAdapter;
import com.sgb.kjwl.view.widget.MaxHeightRecyclerView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * by 2021.03.23  调整布局
 */
public class AttributeViewWindows extends BasePopWindow {
    private MaxHeightRecyclerView recyclerView;
    private TextView okView;
    private TextView resetView;
    private List<AttributeViewEntity.TypeBean> unitTypeList = new ArrayList<>();
    private String name = "";

    private AttributeViewAdapter attributeViewAdapter;

    private List<AttributeViewEntity> attributeViewEntityList;


    public AttributeViewWindows(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.item_attribute_view;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.skill_list);
        okView = holder.getPop().findViewById(R.id.ok_view);
        resetView = holder.getPop().findViewById(R.id.reset_view);
        okView.setOnClickListener(v -> {
            dissMiss();
            if (onResultClick != null) {
                onResultClick.result(attributeViewAdapter.getAttributeString(), null, null);
            }
        });
        resetView.setOnClickListener(v -> dismiss());
        attributeViewAdapter = new AttributeViewAdapter(mContext, null);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(attributeViewAdapter);
    }

    public void setData(List<AttributeViewEntity> attributeViewEntityList, boolean isUpdate) {
        attributeViewAdapter.clearAttributeString();
        this.attributeViewEntityList = attributeViewEntityList;
        attributeViewAdapter.setDatas(attributeViewEntityList);
    }
}
